package com.exam.serviceimpl;
//实现service接口的类，通常包含具体的业务逻辑。
import com.exam.entity.Admin;
import com.exam.mapper.AdminRepository;
import com.exam.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    private final AdminRepository adminRepository;

    @Autowired
    public AdminServiceImpl(AdminRepository adminRepository) {
        this.adminRepository = adminRepository;
    }

    @Override
    public List<Admin> findAll() {
        return adminRepository.findAll(); // 查询所有管理员
    }

    @Override
    public Admin findById(Integer adminId) {
        return adminRepository.findById(adminId).orElse(null); // 根据ID查询管理员
    }

    @Override
    public Admin add(Admin admin) {
        return adminRepository.save(admin); // 添加管理员
    }

    @Override
    public Admin update(Admin admin) {
        return adminRepository.save(admin); // 更新管理员
    }

    @Override
    public void deleteById(Integer adminId) {
        adminRepository.deleteById(adminId); // 根据ID删除管理员
    }
}